package practice.demo.queue;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import javax.jms.JMSException;

/**
 * @ClassName: Reader
 * @Description: TODO
 * @author YuanMingjie
 * @date May 27, 2020 10:40:37 PM
 * 
 */
public class Reader {
	static char message[] = new char[10000];

	public static String getReader(String path) throws IOException {
		String encoding = "UTF-8";// 设置编码格式
		File file = new File(path);
		if (file.isFile() && file.exists()) { // 判断文件是否存在
			InputStreamReader read = new InputStreamReader(new FileInputStream(file), encoding);// 考虑到编码格式
			BufferedReader bufferedReader = new BufferedReader(read);
			String lineTxt = null;

			TopicProducer producer = new TopicProducer();
			String[] array = new String[10];
			lineTxt = bufferedReader.readLine();
			try {
				producer.producer(lineTxt);
			} catch (JMSException e) {
				e.printStackTrace();
			}
			System.out.println(lineTxt);
			return lineTxt;
		} else {
			System.out.println("Cannot find the specified file");
			return null;
		}

	}

	public static List<String> getManyFile(String package1) throws IOException {
		String path = package1;
		List<String> list = new ArrayList();
		list = GetPath.getFile(path);
		List<String> way = new ArrayList();
		for (int i = 0; i < list.size(); i++) {
			way.add(getReader(list.get(i)));
		}
		return way;
	}


}
